// 将数组拆分成多个 size 长度的区块
export const arrChunk = (arr, size=1) => {
    var result = [];
    var l = arr.length; //数组的长度
    var s = Math.ceil(l/size)//  假如我们有长度为10的数组，size传入的是3，是要分成4个自数组的。
    for(var i =0;i<s;i++){
      result[i] = arr.slice(size*i,size*(i+1))
    }
    return result
};

export const setStore = (name, content) => {
    if (!name) return;
    if (typeof content !== 'string') {
        content = JSON.stringify(content);
    }
    localStorage.setItem(name, content);
};
export const getStore = name => {
    if (!name) return;
    return localStorage.getItem(name) && JSON.parse(localStorage.getItem(name));
};

export const setSession = (name, content) => {
    if (!name) return;
    if (typeof content !== 'string') {
        content = JSON.stringify(content);
    }
    sessionStorage.setItem(name, content);
};
export const getSession = name => {
    if (!name) return;
    return sessionStorage.getItem(name) && JSON.parse(sessionStorage.getItem(name));
};